#region File Description
//-----------------------------------------------------------------------------
// ParticleProcessor.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Particle3DSample;
#endregion

namespace ParticlePipeline
{
    /// <summary>
    /// Custom Content Pipeline processor class for particle system settings.
    /// </summary>
    [ContentProcessor]
    class ParticleProcessor : ContentProcessor<ParticleSettings,
                                               ParticleSettings>
    {
        public override ParticleSettings Process(ParticleSettings input,
                                                        ContentProcessorContext context)
        {
            // Create an effect material describing how we want to draw these particles.
            EffectMaterialContent effect = new EffectMaterialContent();

            // Set the effect to be used by this material.
            effect.Effect = new ExternalReference<EffectContent>(
                                                        "ParticleEffect.fx");

            // Set the texture to be used by this material.
            effect.Textures["Texture"] = new ExternalReference<TextureContent>(
                                                        input.TextureName + ".png");

            // Set parameters describing how the material should be rendered.
            effect.OpaqueData.Add("Duration", (float)input.Duration.TotalSeconds);
            effect.OpaqueData.Add("DurationRandomness", input.DurationRandomness);
            effect.OpaqueData.Add("Gravity", input.Gravity);
            effect.OpaqueData.Add("EndVelocity", input.EndVelocity);
            effect.OpaqueData.Add("MinColor", input.MinColor.ToVector4());
            effect.OpaqueData.Add("MaxColor", input.MaxColor.ToVector4());

            effect.OpaqueData.Add("RotateSpeed",
                new Vector2(input.MinRotateSpeed, input.MaxRotateSpeed));

            effect.OpaqueData.Add("StartSize",
                new Vector2(input.MinStartSize, input.MaxStartSize));

            effect.OpaqueData.Add("EndSize",
                new Vector2(input.MinEndSize, input.MaxEndSize));

            return input;
        }
    }
}
